<?php

namespace frontend\modules\comment\models;

use Yii;

/**
 * This is the model class for table "comment_images".
 *
 * @property string $comment_images_id
 * @property string $comment_image
 * @property string $comment_id
 *
 * @property Comment $comment
 */
class CommentImages extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'comment_images';
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
//            TimestampBehavior::className(),
            // 名为myBehavior4的行为，也是给出了MyBehavior类的配置数组
            'uuid' => [
                'class' => \common\behavior\uuidBehavior::className(),
                'owner' => $this
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            ['comment_images_id','default','value'=>$this->getUUID()],
            [['comment_images_id', 'comment_image'], 'required'],
            [['comment_images_id', 'comment_id'], 'string', 'max' => 40],
            [['comment_image'], 'string', 'max' => 255],
            [['comment_id'], 'exist', 'skipOnError' => true, 'targetClass' => Comment::className(), 'targetAttribute' => ['comment_id' => 'comment_id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'comment_images_id' => 'Comment Images ID',
            'comment_image' => 'Comment Image',
            'comment_id' => 'Comment ID',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getComment()
    {
        return $this->hasOne(Comment::className(), ['comment_id' => 'comment_id']);
    }

    /**
     * @inheritdoc
     * @return \frontend\modules\comment\models\query\CommentImagesQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new \frontend\modules\comment\models\query\CommentImagesQuery(get_called_class());
    }
}
